From 2cd3c8627622e866256d4c0dfad98224bf490ea9 Mon Sep 17 00:00:00 2001 From: Sondre Lefsaker Date: Wed, 6 May 2015 12:08:43 +0200 Subject: [PATCH] Suggest adding flags to filter the package in the error message --- src/cargo/ops/cargo_compile.rs | 12 ++++++------ tests/test_cargo_rustc.rs | 9 +++++++-- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/cargo/ops/cargo_compile.rs b/src/cargo/ops/cargo_compile.rs index f49a1fb34..f2b276cf7 100644 --- a/src/cargo/ops/cargo_compile.rs +++ b/src/cargo/ops/cargo_compile.rs @@ -168,16 +168,16 @@ pub fn compile_pkg(package: &Package, options: &CompileOptions) let targets = try!(generate_targets(to_build, mode, filter, release)); let target_with_args = match *target_rustc_args { - Some(args) => { - if targets.len() > 1 { - return Err(human("extra arguments to `rustc` can only be \ - invoked for one target")) - } + Some(args) if targets.len() == 1 => { let (target, profile) = targets[0]; let mut profile = profile.clone(); profile.rustc_args = Some(args.to_vec()); Some((target, profile)) - }, + } + Some(_) => + return Err(human("extra arguments to `rustc` can only be passed to one target, \ + consider filtering\nthe package by passing e.g. `--lib` or \ + `--bin NAME` to specify a single target")), None => None, }; diff --git a/tests/test_cargo_rustc.rs b/tests/test_cargo_rustc.rs index 3729558c9..800051793 100644 --- a/tests/test_cargo_rustc.rs +++ b/tests/test_cargo_rustc.rs @@ -6,6 +6,11 @@ use hamcrest::{assert_that}; fn setup() { } +fn cargo_rustc_error() -> &'static str { + "extra arguments to `rustc` can only be passed to one target, consider filtering\n\ + the package by passing e.g. `--lib` or `--bin NAME` to specify a single target" +} + test!(build_lib_for_foo { let p = project("foo") .file("Cargo.toml", r#" @@ -118,7 +123,7 @@ test!(fails_when_trying_to_build_main_and_lib_with_args { .arg("--").arg("-Z").arg("unstable-options"), execs() .with_status(101) - .with_stderr("extra arguments to `rustc` can only be invoked for one target")); + .with_stderr(cargo_rustc_error())); }); test!(build_with_args_to_one_of_multiple_binaries { @@ -178,7 +183,7 @@ test!(fails_with_args_to_all_binaries { .arg("--").arg("-Z").arg("unstable-options"), execs() .with_status(101) - .with_stderr("extra arguments to `rustc` can only be invoked for one target")); + .with_stderr(cargo_rustc_error())); }); test!(build_with_args_to_one_of_multiple_tests { -- 2.30.2